package com.umakr.demo.controller;

import com.umakr.demo.model.NBTree;
import com.umakr.demo.model.Nianji;
import com.umakr.demo.service.NBTreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * Created by yangliu on 2017/8/4.
 */
@RequestMapping("/demoController")
@Controller
public class DemoController {
    @RequestMapping("/")
    public ModelAndView shoW(){
        ModelAndView mav = new ModelAndView();
        mav.setViewName("demo/search");
        return mav;
    }

    @RequestMapping(value = "/ajax",method = RequestMethod.GET)
    @ResponseBody
    public Object show(@RequestParam(value = "str") String str){

        return  str;
    }





    String username="";
    @RequestMapping("/showAccordion")
    @ResponseBody
    public ModelAndView showAccordion(String userName){
        username = userName;
        ModelAndView mav = new ModelAndView();
        System.out.println(userName);
        mav.addObject("username",userName);
        mav.setViewName("demo/accordion");
        return mav;
    }
    @RequestMapping("/showuserName")
    @ResponseBody
    public String showuserName(){
        System.out.println(username);
        return username;
    }



    @RequestMapping("/page")
    public String page(){
        return "demo/aside";

    }

//    tree
//    @Autowired
//    NBTreeService nbTreeService;
//    List<Long> nianji;
//    @RequestMapping("/showNianji")
//    public void showNianji(Long tid){
//        nianji = nbTreeService.showNianji(tid);
//        List<NBTree> list = null ;
//        for(int i=0;i<nianji.size();i++){
//          NBTree  Nianji = nbTreeService.findByNid(nianji.get(i));
//          list.add(Nianji);
//    }
//        System.out.println(list);
//    }
//
//    @RequestMapping("/showTree")
//    public String showTree(){
//        return "demo/tree";
//    }
//
//    @RequestMapping("/treeDate")
//    @ResponseBody
//    public List<NBTree> treeDate(){
//        List<NBTree> root = nbTreeService.findById((long)1);
//        return buildTree(root);
//    }
//    public List<NBTree> buildTree(List<NBTree> root){
//        for(int i=0;i<root.size();i++){
//            List<NBTree> children = nbTreeService.findByPid(root.get(i).getId());
//            buildTree(children);
//            root.get(i).setChildren(children);
//        }
//        System.out.println(root);
//        return root;
//    }




}
